package com.zzzy.cont.controller;

import com.zzzy.common.vo.AjaxResult;
import com.zzzy.common.vo.PageResult;
import com.zzzy.cont.dao.entity.ConNotifyMessage;
import com.zzzy.cont.dao.entity.Contract;
import com.zzzy.cont.service.ConNotifyMessageService;
import com.zzzy.cont.service.ConService;
import com.zzzy.cont.vo.notify.ConNotifyMessagePageReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;


/**
 * 提醒消息
 *
 * @author fc
 * @since 2024-07-25
 */
@Tag(name = "提醒消息", description = "con600")
@Validated
@RestController
@RequestMapping("/con/notifyMessage")
public class ConNotifyMessageController {

    @Resource
    private ConNotifyMessageService conNotifyMessageService;
    @Resource
    private ConService conService;

    @Operation(summary = "分页列表")
    @GetMapping(value = "/page")
    public AjaxResult<PageResult<ConNotifyMessage>> page(@Valid @ParameterObject ConNotifyMessagePageReq queryReq) {
        PageResult<ConNotifyMessage> conNotifyMessagePage = conNotifyMessageService.getConNotifyMessagePage(queryReq);
        return AjaxResult.success(conNotifyMessagePage);
    }

    @Operation(summary = "标记消息已读")
    @PutMapping("/markNotifyMessageRead/{ids}")
    public AjaxResult markNotifyMessageRead(@NotNull(message = "消息ID不能为空") @PathVariable("ids") Long[] ids){
        conNotifyMessageService.markNotifyMessageRead(ids);
        return AjaxResult.success();
    }

    @Operation(summary = "获取合同信息")
    @Parameter(name = "id", description = "合同ID", required = true)
    @GetMapping("/getContract/{conId}")
    public AjaxResult<Contract> getContract(@NotNull(message = "合同ID不能为空") @PathVariable("conId") Long conId){
        return AjaxResult.success(conService.getConByIdForQuery(conId));
    }
}
